Link Server: SQL to SQL


Create Login on Remote Server that is the server for which we have to create the Link Server, in this case 192.168.8.31,1434 is my RemoteServer and  "TestLogin"  Login is created where its server role is public, User mapping  to Database "Testing" and assigned DataReader Role to it.


Now follow these step to create linked server on Local Server  i.e 192.168.8.31,1433 using any sysadmin Login.



In security tab select "Not be made" option and specify the Local account from drop-down list also specify the remote login which we have created in earlier step i.e remote Login Account "TestLogin"







Click on Ok now Link Server is created for "sa" user only. No user other than sa can use link server.

Let's try,
Login to your server with sa account where you have created Linked Server and under "Server Object" right click on Linked Server which was created, then click on "Test Connection




As you can see Test connection succeeded.


Quering using openrowset query:
CRUD operations:
By using the OPENQUERY function we can execute the specified pass-through queries on the specified Linked Server and return the output.

Sample Select Syntax

SELECT * FROM OPENQUERY(LinkServerName, 'select * from dbo.Products')
Call a function or Stored Procedure

SELECT * FROM OPENQUERY(LinkServerName, 'EXEC [dbo].[CustOrdersOrders] Anurag')
Insert records

insert OPENQUERY(LinkServerName, 'select ProductName, Description from dbo.Products')

select 'Testing', 'Testing'
To insert records we need to first select those columns to which records are to be inserted and pass the values through the select statement. Update records

update OPENQUERY(LinkServerName, 'select ProductName from dbo.Products where ProductID=10')
set ProductName = 'New Test'
To update records we need to first select those columns to which records are to be updated and pass the values through the select statement with column names. We can have multiple column names separated with a comma. Delete records

delete OPENQUERY(LinkServerName, 'select * from dbo.Products where ProductID in (9, 10, 11)')

We just need to select those records to be deleted and execute the delete statement.

Restrict the access for Linked Server To Users:




Create Login on Remote Server that is the server for which we have to create the Link Server, in this case 192.168.8.31,1434 is my RemoteServer and  "TestLogin"  Login is created where its server role is public, User mapping  to Database "Testing" and assigned DataReader Role to it.



Now Login to your server with any other account excluding "sa" account where you have created Linked Server and under "Server Object" right click on Linked Server which was created, then click on "Test Connection".





As you can see we are unable to test connection as well as unable to query link server.
Now Login to your server with any other account which does not have "sysadmin" rights means normal user.

Here I have login to server using SQL authentication i.e "dd"  which is public user.
Check linked server under "Server Object". You will find that link server is not visible to normal user as we have specified only "sa" account during creation of linked server.



If you specify "dd" user in linked Server then link server will be visible and available to query.







Name

Azure Backup Database Clustering Crash Dumps DBCC Deadlock Link Server Log Shipping Maintenance Migration Mirroring Monitoring Performance Tuning Permissions Post Installations Prerequisites Replication Restore Database SQL Installations SQL on Linux SQL Uninstallations SSIS T-SQL Windows Server
false
ltr
item
hybriddba.blogspot.com: Link Server: SQL to SQL
Link Server: SQL to SQL
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyoCjDlypm0PkyH07z78Sdsv5-bxovlRrW6Z4uSlqyyVIykcom78dT3hxnblAQYsvjDuiTzHs-FhbtR5o8Xl8eb05kjpYHyfAgUJY7524vjGqv2Xp1EgudLIYl_lrqMV8ZUiljZqJDKFM7/s1600/1579258080281380-0.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyoCjDlypm0PkyH07z78Sdsv5-bxovlRrW6Z4uSlqyyVIykcom78dT3hxnblAQYsvjDuiTzHs-FhbtR5o8Xl8eb05kjpYHyfAgUJY7524vjGqv2Xp1EgudLIYl_lrqMV8ZUiljZqJDKFM7/s72-c/1579258080281380-0.png
hybriddba.blogspot.com
https://hybriddba.blogspot.com/2019/06/link-server-sql-to-sql.html
https://hybriddba.blogspot.com/
https://hybriddba.blogspot.com/
https://hybriddba.blogspot.com/2019/06/link-server-sql-to-sql.html
true
7679493960263860249
UTF-8
Not found any posts Not found any related posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU Tag ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Contents See also related Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy